{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# So easy, *voilà*!\n",
    "\n",
    "In this example notebook, we demonstrate how Voilà can render custom interactive matplotlib figures using the [ipympl](https://github.com/matplotlib/ipympl) widget."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%matplotlib widget\n",
    "import ipympl\n",
    "\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "x = np.linspace(0, 2 * np.pi, 500)\n",
    "y1 = np.sin(x)\n",
    "y2 = np.sin(3 * x)\n",
    "\n",
    "fig, ax = plt.subplots()\n",
    "ax.fill(x, y1, 'b', x, y2, 'r', alpha=0.3)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "plt.style.use('ggplot')\n",
    "\n",
    "fig, axes = plt.subplots(ncols=2, nrows=2)\n",
    "ax1, ax2, ax3, ax4 = axes.ravel()\n",
    "\n",
    "# scatter plot (Note: `plt.scatter` doesn't use default colors)\n",
    "x, y = np.random.normal(size=(2, 200))\n",
    "ax1.plot(x, y, 'o')\n",
    "\n",
    "# sinusoidal lines with colors from default color cycle\n",
    "L = 2 * np.pi\n",
    "x = np.linspace(0, L)\n",
    "ncolors = len(plt.rcParams['axes.prop_cycle'])\n",
    "shift = np.linspace(0, L, ncolors, endpoint=False)\n",
    "for s in shift:\n",
    "    ax2.plot(x, np.sin(x + s), '-')\n",
    "ax2.margins(0)\n",
    "\n",
    "# bar graphs\n",
    "x = np.arange(5)\n",
    "y1, y2 = np.random.randint(1, 25, size=(2, 5))\n",
    "width = 0.25\n",
    "ax3.bar(x, y1, width)\n",
    "ax3.bar(x + width, y2, width,\n",
    "        color=list(plt.rcParams['axes.prop_cycle'])[2]['color'])\n",
    "ax3.set_xticks(x + width)\n",
    "ax3.set_xticklabels(['a', 'b', 'c', 'd', 'e'])\n",
    "\n",
    "# circles with colors from default color cycle\n",
    "for i, color in enumerate(plt.rcParams['axes.prop_cycle']):\n",
    "    xy = np.random.normal(size=2)\n",
    "    ax4.add_patch(plt.Circle(xy, radius=0.3, color=color['color']))\n",
    "\n",
    "ax4.axis('equal')\n",
    "ax4.margins(0)\n",
    "\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
